#include <iostream>
#include <map>
#include <cmath>

std::map<std::string, int> num_to_word = {
    {"zero", 0},
    {"one", 1},
    {"two", 2},
    {"three", 3},
    {"four", 4},
    {"five", 5},
    {"six", 6},
    {"seven", 7},
    {"eight", 8},
    {"nine", 9}
};

bool is_prime(int n) {
    if (n <= 1) return false;
    if (n == 2) return true;
    if (n % 2 == 0) return false;
    for (int i = 3; i <= sqrt(n); i += 2) {
        if (n % i == 0) return false;
    }
    return true;
}

int main() {
    std::string word1, word2, word3;
    std::cin >> word1 >> word2 >> word3;
    if (num_to_word.find(word1) == num_to_word.end() ||
        num_to_word.find(word2) == num_to_word.end() ||
        num_to_word.find(word3) == num_to_word.end()) {
        std::cout << "Wrong input" << std::endl;
        return 0;
    }
    int num = num_to_word[word1] * 100 + num_to_word[word2] * 10 + num_to_word[word3];
    if (num < 100 || num > 999) {
        std::cout << "Wrong input" << std::endl;
        return 0;
    }
    int lower_prime = num;
    int upper_prime = num;
    while (true) {
        if (is_prime(lower_prime)) break;
        lower_prime--;
    }
    while (true) {
        if (is_prime(upper_prime)) break;
        upper_prime++;
    }
    if (num - lower_prime <= upper_prime - num) {
        std::cout << lower_prime << std::endl;
    } else {
        std::cout << upper_prime << std::endl;
    }
    return 0;
}